#ifndef LIST_H
#define LIST_H

//#include "global.h"

#define DEF_PROTO(type) \
    struct type; \
    typedef struct type type;

#define DEF_LIST_NODE(type) \
    struct type  *prev; \
    struct type  *next;

DEF_PROTO(LIST_NODE)
DEF_PROTO(LIST)

struct LIST_NODE
{
    DEF_LIST_NODE(LIST_NODE)
};

struct LIST
{
    LIST_NODE  *head;
    LIST_NODE  *tail;
};

#define CAST_LIST(list) ((LIST  *)(list))
#define CAST_NODE(node) ((LIST_NODE  *)(node))

void List_Add(LIST  *list, LIST_NODE  *node);
void List_Insert(LIST  *list, LIST_NODE  *before, LIST_NODE  *node);
void List_Remove(LIST  *list, LIST_NODE  *node);

///////////////////////////////////////////////////////////////

DEF_PROTO(RACK)
DEF_PROTO(RACK_GROUP)

enum RACK_STATE
{
    NOTREADY,
    READY
};

typedef struct STATION_INFO
{
    unsigned short refer;
    unsigned short rackid;
}STATION_INFO;

typedef struct RACK
{
    DEF_LIST_NODE(RACK)

    RACK_GROUP  *parent;

    unsigned char state;            // rack 状态 到位/不到位
    unsigned short rackid;          // 当前rackid
}RACK;

typedef struct RACK_GROUP
{
    DEF_LIST_NODE(RACK_GROUP)

    RACK_GROUP  *predecessor;
    struct LIST racks;
    STATION_INFO *sta;
}RACK_GROUP;

typedef struct FIX
{
    DEF_LIST_NODE(FIX)

    unsigned char fix : 1;                  // 沿类型, 上升沿1，下降沿0
    unsigned char high_count;               // 高电平值数量
    unsigned char low_count;                // 低电平值数量
    unsigned long duration;                 // 与上一个沿之间的间隔
} FIX;


#define CAST_RACK(node)           ((RACK  *)(node))
#define CAST_RACK_GROUP(node)     ((RACK_GROUP  *)(node))
#define CAST_FIX(node)            ((FIX  *)(node))

#endif // LIST_H
